<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>美兰数据文化馆与图书馆</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/huazhi/css/public.css" media="all">
    <link rel="shortcut icon" href="<%=request.getContextPath()%>/huazhi/images/favicon.ico"/>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <blockquote class="layui-elem-quote">
                <div class="layui-inline">
                    <div class="layui-input-inline">
                        <input type="text" class="layui-input" id="year">
                    </div>
                    <button class="layui-btn" id="search_btn" data-type="reload">搜索</button>
                </div>
            </blockquote>
            <table class="layui-hide" id="overyearsTable" lay-filter="overyearsTables"></table>
            <div id="laypage"></div>
        </div>
    </div>
</div>
<input type="hidden" id="curnum" value="1">
<script type="text/html" id="overyearsOperation">
    <shiro:hasPermission name="instrument:overyears:add">
        <div class="layui-inline" lay-event="add" title="添加">
            <i class="layui-icon layui-icon-add-1"></i>
        </div>
    </shiro:hasPermission>
</script>
<script type="text/html" id="table-overyears">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="info">详情</a>
    <shiro:hasPermission name="instrument:overyears:update">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="update"></i>修改</a>
    </shiro:hasPermission>
    <shiro:hasPermission name="instrument:overyears:del">
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
    </shiro:hasPermission>
</script>
<script src="<%=request.getContextPath()%>/huazhi/lib/layui-v2.5.5/layui.all.js"></script>
<script src="<%=request.getContextPath()%>/huazhi/js/lay-config.js?v=1.0.4" charset="utf-8"></script>
<script>
    function child(tid){
        layui.use(['table', 'laydate', 'layer', 'form','laypage'], function () {
            var $ = layui.jquery,
                table = layui.table,
                layer = layui.layer,
                form = layui.form,
                laydate=layui.laydate,
                laypage=layui.laypage;

            //年选择器
            laydate.render({
                elem: '#year'
                ,type: 'year',
                format: 'yyyy年',
                theme: 'molv',
                btns: ['now', 'confirm'],
            });

            var limitcount = 10;
            table.render({
                elem: '#overyearsTable'
                , url: "<%=request.getContextPath()%>/rest/equipment/getListOverYears"
                , toolbar: '#overyearsOperation'
                , height: 'full-193'
                , title: '仪器设备检定信息表'
                , defaultToolbar: ['filter', 'print']
                , cols: [[{field: 'serialnumer', title: '序号', sort: true, rowspan: '2', width: 100},
                    {field: 'stationnumber', title: '站内编号', sort: true, rowspan: '2', width: 150},
                    {field: 'assetnumber', title: '资产编号', sort: true, rowspan: '2', width: 150},
                    {field: 'equipmentname', title: '仪器设备名称', sort: true, rowspan: '2', width: 150},
                    {field: 'verificationyear', title: '检定年份', sort: true, rowspan: '2', width: 150},
                    {field: 'verificationcertificate', title: '检定证书', sort: true, rowspan: '2', width: 150},
                    {field: 'resultconfirmation', title: '结果确认', sort: true, rowspan: '2', width: 150},
                    {field: 'intermediatechecks', title: '期间核查', sort: true, rowspan: '2', width: 150},
                    {field: 'usagerecordbook', title: '使用记录本', sort: true, rowspan: '2', width: 150},
                    {title: '操作', toolbar: '#table-overyears', align: "center", width: 200, fixed: "right"}]]
                , page: false
                , limit: limitcount
                ,where:{"equipmenttid":tid}
                , text: {
                    none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                },
                // limits:[10, 20, 30, 40, 50],
                done: function (res, curr, count) {
                    if (res.errorMsg == null) {

                    } else {
                        layer.msg(res.errorMsg);
                    }
                    var curnum = $("#curnum").val();
                    $('.layui-table-fixed-r').removeClass('layui-hide');//列固定右侧
                    laypage.render({
                        elem: 'laypage'
                        , first: '首页'
                        , last: '尾页'
                        , groups: 5
                        , count: count
                        , curr: curnum
                        , limit: limitcount
                        , layout: ['prev', 'page', 'next', 'skip', 'count', 'limit']
                        , limits: [10, 15, 20]
                        , jump: function (obj, first) {
                            if (!first) {
                                curnum = obj.curr;
                                $("#curnum").val(curnum)
                                limitcount = obj.limit;
                                table.reload('overyearsTable', { //表格的id
                                    where: {
                                        page: curnum,
                                        limit: limitcount
                                    }
                                })

                            }
                        }
                    })
                }
            })


            //监听工具条
            table.on('tool(overyearsTables)', function (obj) {  //表格的lay-filter="userlists"
                var data = obj.data; //获得当前行所有数据
                var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
                var tr = obj.tr; //获得当前行 tr 的DOM对象
                if (obj.event === 'del') {
                    deletes(data, obj);
                } else if (obj.event === 'update') {
                    update(data);
                } else if (obj.event === 'info') {
                    info(data)
                }
            });


            function deletes(data, obj) {
                layer.confirm('确定删除此数据', {icon: 3, title: '提示信息'}, function (index) {
                    var index = layer.msg('删除中，请稍候', {icon: 16, time: false, shade: 0.6});
                    setTimeout(function () {
                        //向服务端发送删除指令
                        $.ajax({
                            type: "post",
                            url: "<%=request.getContextPath()%>/rest/equipment/deleteOverYears",
                            data: "tid=" + data.tid,
                            dataType: "json",
                            async: false,
                            success: function (msg) {
                                layer.close(index);
                                if (msg == true) {
                                    layer.msg('删除成功');
                                    obj.del();
                                } else {
                                    layer.msg(msg.errorMsg);
                                }
                            }
                        })
                    }, 2000);
                });
            }

            function update(data) {
                var clocess = "1";
                layer.open({
                    title: "修改",
                    type: 2,
                    content: '<%=request.getContextPath()%>/rest/getRoute?type=instrument&url=overyears_update',
                    //是否显示右上角关闭图标，默认为1，显示
                    area: ['90%', '91%'],
                    maxmin: true,
                    shade: 0.6,
                    anim: 4,
                    skin: 'layui-layer-molv',
                    resize: true,
                    success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                        var iframe = window['layui-layer-iframe' + index];
                        iframe.child(data.tid)
                    }, cancel: function (index, layero) {
                        layer.close(index)
                        clocess = "2"
                        return false;
                    },
                    end: function () {
                        if (clocess == "2") {

                        } else {
                            table.reload('overyearsTable')
                        }
                        return false;
                    }
                });
            }

            function info(data) {
                layer.open({
                    title: "详情",
                    type: 2,
                    content: '<%=request.getContextPath()%>/rest/getRoute?type=instrument&url=overyears_info',
                    //是否显示右上角关闭图标，默认为1，显示
                    area: ['90%', '91%'],
                    maxmin: true,
                    shade: 0.6,
                    anim: 4,
                    skin: 'layui-layer-molv',
                    resize: true,
                    success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                        var iframe = window['layui-layer-iframe' + index];
                        iframe.child(data.tid)
                    }
                });
            }




            //搜索事件
            var active = {
                reload: function () {  //data-type='reload'
                    var year = $('#year').val();
                    $("#curnum").val("1");
                    table.reload('overyearsTable', { //表格的id
                        where: {
                            year: year,
                            page: 1,
                            limit: 10,
                        },
                        text: {
                            none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
                        }
                    })
                }
            };

            $('#search_btn').on('click', function () { //搜索的id
                var type = $(this).data('type');
                active[type] ? active[type].call(this) : '';
            });

            table.on('toolbar(overyearsTables)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id)
                    , data = checkStatus.data, //获取选中的数据
                    newsId = [];
                switch (obj.event) {
                    case 'add':
                        var clocess = "1";
                        var index = layer.open({
                            title: "添加",
                            type: 2,
                            content: '<%=request.getContextPath()%>/rest/getRoute?type=instrument&url=overyears_add',
                            maxmin: true,
                            area: ['90%', '91%'],
                            //是否显示右上角关闭图标，默认为1，显示
                            anim: 4,
                            shade: 0.6,
                            skin: 'layui-layer-molv',
                            resize: true,
                            cancel: function (index, layero) {
                                layer.close(index)
                                clocess = "2"
                                return false;
                            },
                            success: function (layero, index) {  //当你需要在层创建完毕时即执行一些语句，可以通过该回调 想相当于吧值转到子界面
                                var iframe = window['layui-layer-iframe' + index];
                                iframe.child(tid)
                            },
                            end: function () {
                                if (clocess == "2") {

                                } else {
                                    table.reload('overyearsTable')
                                }
                                return false;
                            }
                        });
//                    $('.layui-layer-setwin .layui-layer-max').css("display", "none")
//                    $('.layui-layer-setwin .layui-layer-min').css("display", "none")
                        break;
                }
                ;
            });


        });
    }
</script>
</body>
</html>
